<?php
/* 
 * ********* CVS HEADER ********* 
 * 
 * $RCSfile: admhtmlcharger.php,v $ 
 * $Date: 2005/10/21 12:58:07 $ 
 * $Revision: 1.3 $ 
 * 
 * ********* CVS HEADER ********* 
 */
if($action=="Charger"){
	require_once(get_path_module('contenu.sauvegarde'));
	$filename= $_FILES['monfichier']['name'];
	$filetmp = $_FILES['monfichier']['tmp_name'];
	if(file_exists($filetmp)&&($filename!=''))
	{
		$fd = fopen($filetmp, "r");
		$content = fread($fd, filesize ($filetmp));
		fclose($fd);
		$droit = $session['id_groupe'];
		
		/**
		  * Chargement des repertoires
		  */
		$pattern1 = "|<rportal::repertoire>(.*)<\/rportal::repertoire>|misU";
	    $count = preg_match_all($pattern1, $content,$sortie,PREG_PATTERN_ORDER);
	    /**
	      * $sortie[0][$i] : avec <rportal::repertoire>
	      * $sortie[1][$i] : sans <rportal::repertoire>
	      */
		for($i=0;$i<$count;$i++){
			if($sortie[1][$i]!=''){
				if(!repertoire_exists($sortie[1][$i])){
					creer_repertoire($sortie[1][$i],$droit);
				}
			}
		}
		
		/**
		  * Chargement des pages
		  */
		$pattern1 = "|<rportal::page>(.*)<\/rportal::page>|misU";
		$count = preg_match_all($pattern1, $content,$sortie,PREG_PATTERN_ORDER);
	    /**
	      * $sortie[0][$i] : avec <rportal::page>
	      * $sortie[1][$i] : sans <rportal::page>
	      */
	    for($i=0;$i<$count;$i++){
			if($sortie[1][$i]!=''){
				// path de la page
				$pattern1 = "|<rportal::path>(.*)<\/rportal::path>|misU";
				$count2 = preg_match_all($pattern1, $sortie[1][$i],$sortie2,PREG_PATTERN_ORDER);
				$path = $sortie2[1][0];
				// type de la page
				$pattern1 = "|<rportal::type>(.*)<\/rportal::type>|misU";
				$count2 = preg_match_all($pattern1, $sortie[1][$i],$sortie2,PREG_PATTERN_ORDER);
				$type = $sortie2[1][0];
				// titre de la page
				$pattern1 = "|<rportal::titre>(.*)<\/rportal::titre>|misU";
				$count2 = preg_match_all($pattern1, $sortie[1][$i],$sortie2,PREG_PATTERN_ORDER);
				$titre = $sortie2[1][0];
				// description de la page
				$pattern1 = "|<rportal::description>(.*)<\/rportal::description>|misU";
				$count2 = preg_match_all($pattern1, $sortie[1][$i],$sortie2,PREG_PATTERN_ORDER);
				$description = $sortie2[1][0];
				// login de l'auteur
				$pattern1 = "|<rportal::login>(.*)<\/rportal::login>|misU";
				$count2 = preg_match_all($pattern1, $sortie[1][$i],$sortie2,PREG_PATTERN_ORDER);
				$auteur = $sortie2[1][0];
				// contenu du fichier
				$pattern1 = "|<rportal::fichier>(.*)<\/rportal::fichier>|misU";
				$count2 = preg_match_all($pattern1, $sortie[1][$i],$sortie2,PREG_PATTERN_ORDER);
				$fichier = $sortie2[1][0];
				// script annexe
				$pattern1 = "|<rportal::script>(.*)<\/rportal::script>|misU";
				$count2 = preg_match_all($pattern1, $sortie[1][$i],$sortie2,PREG_PATTERN_ORDER);
				$script = $sortie2[1][0];
				
				creer_page($path,$type,$titre,$description,$auteur,$fichier,$script,$droit);
			}
		}
	}
	header("Location: ?op=admhtmlnav");
	exit;
}
require_once('module/TPLN/TPLN.php');
$TPLN = new TPLN;
$TPLN->Open($op_basepath.'tpl/admhtmlcharger.html');
$TPLN->IncludeFile("header","environnement/$session[environnement]/header.php"); 
$TPLN->IncludeFile("footer","environnement/$session[environnement]/footer.php");

require_once(get_path_module("admin"));
$pc = new panneau_controle();
$pc->calculRubriqueParFonction($op);
$TPLN->Parse("panneau_controle",$pc->retourneEntete());

$TPLN->Write();
?>